var checkacc=false;//账号检查
var checkpwd=false;//密码检查
var checkpwd2=false;//再次输入密码检查
var checkname=false;//用户名检查
var checkphone=false;//邮箱检查
var checkyzm=false;//验证码检查
var yzmcount=1;//只发一次验证码判断
function showZhuce(){//login-register.jsp界面中 onclick方法，用于a标签，显示注册界面。隐藏登录界面
	document.getElementById('zhucediv').style.display="block";
	document.getElementById('dengludiv').style.display="none";
}
function showDenglu(){//login-register.jsp界面中 onclick方法，用于a标签，显示登录 界面。隐藏注册界面
	document.getElementById('dengludiv').style.display="block";
	document.getElementById('zhucediv').style.display="none";
	document.getElementById("wangjimimadiv").style.display="none";
}
function birthday(){//my-account.jsp界面中onload方法 加载生日初始化
	$('#user_birth').val("${user.ubirth}");
}
function gaibian() {//my-account.jsp界面中 onclick方法 取消输入框只读属性，确定按钮取消按钮设置可见，修改按钮设置隐藏
	document.getElementById("queding").type = "botton";
	document.getElementById("quxiao").type = "botton";
	document.getElementById("xiugai").type = "hidden";
	document.getElementById("user_name").removeAttribute("readonly");
	document.getElementById("user_sex").removeAttribute("readonly");
	document.getElementById("user_city").removeAttribute("readonly");
	document.getElementById("user_phone").removeAttribute("readonly");
	document.getElementById("user_email").removeAttribute("readonly");
	document.getElementById("user_birth").removeAttribute("readonly");
}
function quxiaoxiugai() {//my-account.jsp界面中 onclick方法 输入框设置只读属性，确定按钮取消按钮设置隐藏，修改按钮设置显示
	document.getElementById("queding").type = "hidden";
	document.getElementById("quxiao").type = "hidden";
	document.getElementById("xiugai").type = "botton";
	document.getElementById("user_name").readOnly = "false";
	document.getElementById("user_sex").readOnly = "false";
	document.getElementById("user_city").readOnly = "false";
	document.getElementById("user_phone").readOnly = "false";
	document.getElementById("user_email").readOnly = "false";
	document.getElementById("user_birth").readOnly = "false";
}
function xiugaiMessage() {//my-account.jsp界面中 onclick方法 调用取消修改方法，将参数打包成json格式发回后端userservlet
	quxiaoxiugai();
	var obj = new Object();
	obj.uname = $('#user_name').val();
	obj.usex = $('#user_sex').val();
	obj.uphone = $('#user_phone').val();
	obj.ucity = $('#user_city').val();
	obj.uemail = $('#user_email').val();
	obj.uconstellation = $('#user_constellation').val();
	var birth=$('#user_birth').val();
	var str = JSON.stringify(obj);
	$.post("UserServlet?type=xiugaiMessage", {xiugai : str,birth:birth}, function(obj) {
		if (obj == 1) {
			alert("修改成功");
		} else {
			alert("修改失败");
		}
	});
}
function accyanzheng(acc){//login-register.jsp界面中 onkeyup方法，用于检测账号是否长度符合，并且使用ajax检测账号是否存在
	if(acc.value.length>=2&&acc.value.length<=6){
		$.ajax({
			url:"signup/checkacc",
			type:"post",
			data:{
				uacc:acc.value
			},
			success:function (obj) {
				if (obj == 0) {
					document.getElementById("acc_error").style.display = "inline";
					document.getElementById("acc_error").innerHTML = '账号已存在';
					checkacc = false;
				} else {
					document.getElementById("acc_error").style.display = "none";
					document.getElementById("acc_error").innerHTML = '';
					checkacc = true;
				}
			}});
		} else {
		document.getElementById("acc_error").style.display="inline";
		document.getElementById("acc_error").innerHTML='错误，长度2-6位';
		checkacc = false;
		}
}
function pwdyanzheng(pwd) {//login-register.jsp界面中 onkeyup方法，用于检测密码强度和长度是否符合
	if (pwd.value.length >= 6 && pwd.value.length <= 16) {
		var heard = 0;
		var xiaoxie = 0, shuzi = 0, daxie = 0, fuhao = 0;
		for ( var i in pwd.value) {
			if (xiaoxie == 0) {
				if (pwd.value.charAt(i) >= "a" && pwd.value.charAt(i) <= "z") {
					heard += 1;
					xiaoxie++;
				}
			}
			if (daxie == 0) {
				if (pwd.value.charAt(i) >= "A" && pwd.value.charAt(i) <= "Z") {
					heard += 1;
					daxie++;
				}
			}
			if (shuzi == 0) {
				if (pwd.value.charAt(i) >= "0" && pwd.value.charAt(i) <= "9") {
					heard += 1;
					shuzi++;
				}
			}
			if (fuhao == 0) {
				if (pwd.value.charAt(i) == "." || pwd.value.charAt(i) <= "-"
						|| pwd.value.charAt(i) == "/"
						|| pwd.value.charAt(i) == "+"
						|| pwd.value.charAt(i) == "*"
						|| pwd.value.charAt(i) == "!") {
					heard += 1;
					fuhao++;
				}
			}
		}
		var str = "";
		if (heard == 1) {
			str = "弱";
		} else if (heard == 2) {
			str = "中";
		} else if (heard == 3) {
			str = "强";
		} else if (heard == 4) {
			str = "超强"
		}
		document.getElementById("pwd_error").innerHTML = "密码强度：" + str+"<br/>";
		checkpwd = true;
	} else {
		document.getElementById("pwd_error").style.display = "inline";
		document.getElementById("pwd_error").innerHTML = '错误，密码长度6~16位'+"<br/>";
		checkpwd = false;
	}
}
function pwd2yanzheng(pwd){//login-register.jsp界面中 onblur方法，检测第二次输入的密码是否相同
	if(pwd.value==document.getElementById("upwd").value&&pwd.value.length>=6){
	document.getElementById('pwd2_error').style.display="none";
	document.getElementById("pwd2_error").innerHTML="";
	checkpwd2=true;
	}
	else{
	document.getElementById("pwd2_error").style.display="inline";
	document.getElementById("pwd2_error").innerHTML='错误，与上次输入密码不符';
	checkpwd2 = false;
	}
}
function nameyanzheng(name){//login-register.jsp界面中 onblur方法，判断用户名长度是否符合
	if(name.value.length<=10){
	document.getElementById('name_error').style.display="none";
	checkname=true;
	}
	else{
	document.getElementById("name_error").style.display="inline";
	document.getElementById("name_error").innerHTML='错误，长度不符';
	checkname = false;
	}
}
function phoneyanzheng(phone){//login-register.jsp界面中 onblur方法，用正则表达式判断手机是否符合规范
	if(/^1[3456789]\d{9}$/.test(phone.value)){
		$.post("signup/checkphone",{uphone:phone.value},function (obj) {
			if(obj==1){
				document.getElementById('yzmdiv').removeAttribute("hidden");
				document.getElementById('phone_error').style.display="none";
				if(yzmcount==1){
                    document.getElementById("phoneyzm").removeAttribute("hidden");
					yzmcount++;
				}
				checkemail=true;
			} else {
				document.getElementById("phone_error").style.display="inline";
				document.getElementById("phone_error").innerHTML='手机号已被注册';
			}
		})
	} else {
        document.getElementById("phone_error").innerHTML="输入格式错误";
		document.getElementById("phoneyzm").hidden="false";
		return false;
	}

}
function sendEmailCode(){//login-register.jsp界面中 onclick方法，用ajax方法发送email给后端，后端返回验证码设置到hiddencode隐藏域中
	document.getElementById("emailyzm").hidden="false";
	var email = $('#uemail').val();
	$.post("signup/emailcode",{uemail:email}, function(obj){
		if(obj==1){
			alert("今日验证码已发送达到上限，请明天再注册");
		} else {
			document.getElementById("uacc").disabled = "false";
			alert("验证码发送成功，请查看邮箱");
		}
	});
}
function sendPhoneCode(){//login-register.jsp界面中 onclick方法，用ajax方法发送email给后端，后端返回验证码设置到hiddencode隐藏域中
	document.getElementById("phoneyzm").hidden="false";
	var phone = document.getElementById("uphone").value;
	$.post("signup/phonecode",{uphone:phone}, function(obj){
		if(obj==1){
			alert("今日验证码已发送达到上限，请明天再注册");
		} else {
			document.getElementById("uacc").disabled = "false";
			alert("验证码发送成功，请查看手机短信");
		}
	});
}
function yzmyanzheng(code){//login-register.jsp界面中 onblur方法，验证码判断
	var value = code.value
	$.post("signup/checkyzm",{yzm:value},function(obj){
		if(obj==0){
			document.getElementById('yzm_error').style.display="none";
			checkyzm=true;
		} else {
			document.getElementById("yzm_error").style.display="inline";
			document.getElementById("yzm_error").innerHTML='验证码输入错误';
			checkyzm=false;
		}
	})
	
}

function panduanConstellation(birth){
	var day = birth.value;
	var time = day.split("-");
	var month = time[1];
	var date=time[2];
	var value = ""; 
	if (month == 1 && date >=20 || month == 2 && date <=18) {value = "水瓶座";}
	if (month == 2 && date >=19 || month == 3 && date <=20) {value = "双鱼座";}
	if (month == 3 && date >=21 || month == 4 && date <=19) {value = "白羊座";}
	if (month == 4 && date >=20 || month == 5 && date <=20) {value = "金牛座";}
	if (month == 5 && date >=21 || month == 6 && date <=21) {value = "双子座";}
	if (month == 6 && date >=22 || month == 7 && date <=22) {value = "巨蟹座";}
	if (month == 7 && date >=23 || month == 8 && date <=22) {value = "狮子座";}
	if (month == 8 && date >=23 || month == 9 && date <=22) {value = "处女座";}
	if (month == 9 && date >=23 || month == 10 && date <=22) {value = "天秤座";}
	if (month == 10 && date >=23 || month == 11 && date <=21) {value = "天蝎座";}
	if (month == 11 && date >=22 || month == 12 && date <=21) {value = "射手座";}
	if (month == 12 && date >=22 || month == 1 && date <=19) {value = "摩羯座";}
	$('#user_constellation').val(value);
}

function checkAll(){//login-register.jsp界面中 onsubmit方法
	if(checkacc){
		if(checkpwd){
			if(checkpwd2){
				if(checkname){
						if(checkyzm){
							return ture;
						} else {
							alert("验证码输入错误");
						}
					} else {
					alert("用户名格式有误");
				}
			} else {
				alert("两次输入的密码不同");
			}
		} else {
			alert("密码格式有误");
		}
	} else {
		alert("账号格式有误");
	}
	return checkacc&&checkpwd&&checkpwd2&&checkname&&checkemail&&checkyzm;
}
var ksyzmcount = 1;
function ksloginAcc(acc) { //快速登录的邮箱手机判断
	var reg = new RegExp("^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$"); //正则表达式
	if(/^1[3456789]\d{9}$/.test(acc.value)){
		$.post("signup/checkphone",{uphone:acc.value},function (obj) {
			if(obj==0){
				document.getElementById('uphone').value=acc.value;
				document.getElementById('login_error').style.display="none";
				if(ksyzmcount==1){
					document.getElementById("phoneyzm").removeAttribute("hidden");
					ksyzmcount++;
				}
				checkemail=true;
			} else {
				document.getElementById("login_error").style.display="inline";
				document.getElementById("login_error").innerHTML='该电话号码未注册';
			}
		});
	} else if (reg.test(acc.value)){
		$.post("signup/checkemail",{uemail:acc.value},function (obj) {
			if(obj==0){
				document.getElementById('uemail').value=acc.value;
				document.getElementById('login_error').style.display="none";
				if(ksyzmcount==1){
					document.getElementById("emailyzm").removeAttribute("hidden");
					ksyzmcount++;
				}
				checkemail=true;
			} else {
				document.getElementById("login_error").style.display="inline";
				document.getElementById("login_error").innerHTML='该邮箱未注册';
			}
		});
	}
}
function showptlogin() {//显示普通登录
	document.getElementById("ptlogin").removeAttribute("hidden");
	document.getElementById("kslogin").hidden="false";
}
function showkslogin() {//显示快速登录
	document.getElementById("kslogin").removeAttribute("hidden");
	document.getElementById("ptlogin").hidden="false";
}


function buildMap() {
	var map = new BMapGL.Map("container");
	var point = new BMapGL.Point(116.404, 39.915); 
	map.centerAndZoom('厦门市', 12);
	map.enableScrollWheelZoom(true); //开启鼠标滚轮缩放
	map.setMapType(BMAP_EARTH_MAP); //地球模式
	var scaleCtrl = new BMapGL.ScaleControl(); // 添加比例尺控件
	map.addControl(scaleCtrl);
	var zoomCtrl = new BMapGL.ZoomControl(); // 添加缩放控件
	map.addControl(zoomCtrl);
	var cityCtrl = new BMapGL.CityListControl(); // 添加城市列表控件
	map.addControl(cityCtrl);
	map.setTilt(20); // 设置地图初始倾斜角度
	
//	var map = new BMapGL.Map("container");  //设置开车路线
//	map.centerAndZoom(new BMapGL.Point(116.404, 39.915), 11);
//	var p1 = new BMapGL.Point(116.301934, 39.977552);
//	var p2 = new BMapGL.Point(116.508328, 39.919141);
//	var driving = new BMapGL.DrivingRoute(map, { renderOptions: { map: map, autoViewport: true } });
//	driving.search(p1, p2);
	

	//				var marker = new BMapGL.Marker(point); // 创建标注   
	//				map.addOverlay(marker); // 将标注添加到地图中
	//				marker.addEventListener("click", function() {
	//					alert("您点击了标注");
	//				});
	//				var prism = new BMapGL.Prism(path, 5000, {
	//					topFillColor: '#5679ea',
	//					topFillOpacity: 0.5,
	//					sideFillColor: '#5679ea',
	//					sideFillOpacity: 0.9
	//				});
	//				map.addOverlay(prism);//3D棱柱添加

}

var zhemail = false;//找回 email的验证
var zhacc = false;//找回账号的验证
var zhpwd = false;//密码判断
var zhpwd2 = false;//再次输入密码判断
var zhyzm = false;//验证码判断
 
function sendEmailCode2(){//login-register.jsp界面中 onclick方法，用ajax方法发送email给后端，后端返回验证码设置到hiddencode隐藏域中
	document.getElementById("zhaohuibtn_yzm").type="hidden";
	var email = $('#zhaohui_email').val();
	$.post("UserServlet?type=emailCode",{email:email}, function(obj){
		if(obj==2){
			alert("今日验证码已发送达到上限，请明天再注册");
		} else {
			alert("验证码发送成功，请查看邮箱");
		}
	});
}

function zhaohuiEmail(email){//login-register.jsp界面中 onblur方法，用正则表达式判断邮箱是否符合规范   ajax去数据库中根据账号查找邮箱是否对应
	var reg = new RegExp("^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$"); //正则表达式
	var obj = email.value; //要验证的对象
	if(obj == "") { //输入不能为空
		$("#zhemail_error").html("输入不能为空");
		document.getElementById('zhaohuiyzmdiv').style.display="none";
		return false;
	} else if(!reg.test(obj)) { //正则验证不通过，格式不对
		$("#zhemail_error").html("输入格式错误");
		document.getElementById('zhaohuiyzmdiv').style.display="none";
		return false;
	} else {
		$.post("UserServlet?type=checkEmail",{email:email.value,acc:$("#zhaohui_acc").val()},function(obj){
			if(obj==1){
				document.getElementById('zhaohuiyzmdiv').style.display="block";
				document.getElementById('zhemail_error').style.display="none";
				if(yzmcount==1){
					document.getElementById("zhaohuibtn_yzm").type="button";
					yzmcount++;
				}
				zhemail=true;
			} else {
				document.getElementById("zhemail_error").style.display="inline";
				document.getElementById('zhemail_error').innerHTML="账号与邮箱不匹配";
				document.getElementById('zhaohuiyzmdiv').style.display="none";
				zhemail=false;
			}
		});
	}
}

function zhaohuiacc(acc){//login-register.jsp界面中 onkeyup方法，检测账号是否在数据库中存在
	if(acc.value.length>=2&&acc.value.length<=6){
		$.post("UserServlet?type=AccCheck",{acc:acc.value},function(obj){
			if(obj==0){
				document.getElementById("zhacc_error").style.display="none";
				checkacc=true;
			} else {
				$('#zhacc_error').html("账号不存在");
				zhacc=false;
			}
		});
		} else {
		document.getElementById("zhacc_error").style.display="inline";
		document.getElementById("zhacc_error").innerHTML='错误，长度2-6位';
		zhacc = false;
		}
}
function pwdzhaohui(pwd){//login-register.jsp界面中 onkeyup方法，用于检测密码强度和长度是否符合
	if (pwd.value.length >= 6 && pwd.value.length <= 16) {
		var heard = 0;
		var xiaoxie = 0, shuzi = 0, daxie = 0, fuhao = 0;
		for ( var i in pwd.value) {
			if (xiaoxie == 0) {
				if (pwd.value.charAt(i) >= "a" && pwd.value.charAt(i) <= "z") {
					heard += 1;
					xiaoxie++;
				}
			}
			if (daxie == 0) {
				if (pwd.value.charAt(i) >= "A" && pwd.value.charAt(i) <= "Z") {
					heard += 1;
					daxie++;
				}
			}
			if (shuzi == 0) {
				if (pwd.value.charAt(i) >= "0" && pwd.value.charAt(i) <= "9") {
					heard += 1;
					shuzi++;
				}
			}
			if (fuhao == 0) {
				if (pwd.value.charAt(i) == "." || pwd.value.charAt(i) <= "-"
						|| pwd.value.charAt(i) == "/"
						|| pwd.value.charAt(i) == "+"
						|| pwd.value.charAt(i) == "*"
						|| pwd.value.charAt(i) == "!") {
					heard += 1;
					fuhao++;
				}
			}
		}
		var str = "";
		if (heard == 1) {
			str = "弱";
		} else if (heard == 2) {
			str = "中";
		} else if (heard == 3) {
			str = "强";
		} else if (heard == 4) {
			str = "超强"
		}
		document.getElementById("zhpwd_error").innerHTML = "密码强度：" + str+"<br/>";
		zhpwd = true;
	} else {
		document.getElementById("zhpwd_error").style.display = "inline";
		document.getElementById("zhpwd_error").innerHTML = '错误，密码长度6~16位'+"<br/>";
		zhpwd = false;
	}
	
}
function pwd2zhaohui(pwd){//login-register.jsp界面中 onblur方法，检测第二次输入的密码是否相同
	if(pwd.value==$("#zhaohui_pwd").val()&&pwd.value.length>=6){
	document.getElementById('zhpwd2_error').style.display="none";
	zhpwd2=true;
	}
	else{
	document.getElementById("zhpwd2_error").style.display="inline";
	document.getElementById("zhpwd2_error").innerHTML='错误，与上次输入密码不符';
	zhpwd2 = false;
	}
}

function yzmyanzheng1(code){//login-register.jsp界面中 onblur方法，验证码判断
	var value = code.value
	$.post("UserServlet?type=yzmCheck",{yzm:value},function(obj){
		if(obj==1){
			document.getElementById('zhyzm_error').style.display="none";
			zhyzm=true;
		} else {
			document.getElementById("zhyzm_error").style.display="inline";
			document.getElementById("zhyzm_error").innerHTML='验证码输入错误';
			zhyzm=false;
		}
	})
}

function zhaohuicheck(){
	return zhemail&&zhacc&&zhpwd&&zhpwd2&checkyzm&&zhyzm;
}

function wangjimima(){
	document.getElementById("dengludiv").style.display="none";
	document.getElementById("wangjimimadiv").style.display="block";
}